/**
 * 
 */
package str845_paski_przewijania_awt;

import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

public class ScrollBarDemo extends Applet 
		implements AdjustmentListener, MouseMotionListener {
	private String msg = "";
	private Scrollbar vertSB, horzSB;
	
	@Override
	public void init() {
		setSize(700, 500);
		
		int width = Integer.parseInt(getParameter("width"));
		int height = Integer.parseInt(getParameter("height"));
		
		vertSB = new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, height);
		vertSB.setPreferredSize(new Dimension(20, 100));
		
		horzSB = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, width);
		horzSB.setPreferredSize(new Dimension(100, 20));
		
		add(vertSB);
		add(horzSB);
		
		vertSB.addAdjustmentListener(this);
		horzSB.addAdjustmentListener(this);
	
		addMouseMotionListener(this);
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		int x = e.getX();
		int y = e.getY();
		vertSB.setValue(y);
		horzSB.setValue(x);
		repaint();
	}

	@Override
	public void mouseMoved(MouseEvent e) {}

	@Override
	public void adjustmentValueChanged(AdjustmentEvent e) {
		repaint();
	}

	@Override
	public void paint(Graphics g) {
		msg = "Pionowy: " + vertSB.getValue();
		msg += ", Poziomy: " + horzSB.getValue();
		g.drawString(msg, 6, 160);
		
		// wyswietla biezaca pozycje przeciaganego kursora myszy
		g.drawString("*", horzSB.getValue(), vertSB.getValue());
	}
	

}
